/** 
 * File-Name:UserAction.java
 *
 * Created on 2011-6-2 下午10:22:05
 * 
 * @author: Neo (neolimeng@gmail.com)
 * Software Engineering Institute, Peking University, China
 * 
 * Copyright (c) 2009, Peking University
 * 
 *
 */
package site.web;

import neoutil.CommonAction;

import org.apache.log4j.Logger;

import site.entity.User;
import site.service.repository.UserRepository;

/**
 * Description:
 * 
 * @author: Neo (neolimeng@gmail.com) Software Engineering Institute, Peking
 *          University, China
 * @version 1.0 2011-6-2 下午10:22:05
 */
public class UserAction extends CommonAction {
	private static Logger log = Logger.getLogger(UserAction.class);
	private User user;
	private String email;
	private String password;

	public String login() {
		try {
			if (null == email || null == password || "".equals(email)
					|| "".equals(password)) {
				log.error("Login: 参数错误！");
				return INPUT;
			} else {
				UserRepository userRepository = new UserRepository();
				user = userRepository.login(email, password);
				if (user == null) {
					log.error("Login: 用户不存在！");
					return INPUT;
				} else {
					setSessionObject("loginUser", user);
					log.info("Login: " + email + "登陆成功！！");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	public String relogin() {
		try {
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	public String logout() {
		try {
			setSessionObject("loginUser", null);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
